#include <iostream>
#include <functional>
#include <map>
using namespace std;

int add(int x,int y)
{
    return x+y;
}

int minux(int x,int y)
{
    return x-y;
}
typedef int(*MINUS)(int x,int y);

class Divide{
public:
    int operator ()(int x,int y)
    {
        return x/y;
    }
};

int main()
{
    auto op = function<int(int,int)>(add);
    cout<<op(1,4)<<endl;

    MINUS mi = minux;
    op = function<int(int,int)>(mi);
    cout<<op(4,5)<<endl;

    auto mul = [](int x,int y){
        return x*y;
    };//一般用这个组

    op = function<int(int,int)>(mul);
    cout<<op(4,5)<<endl;


    Divide d;//仿函数
    op = function<int(int,int)>(d);
    cout<<op(10,3)<<endl;
    cout<<d(10,2)<<endl;
    cout<<"============================"<<endl;


    map<string,function<int(int,int)>> mp = {
        {"+",add},
        {"-",mi},
        {"*",mul},
        {"/",d}
    };
    cout<<mp["+"](2,4)<<endl;
    cout<<mp["-"](10,1)<<endl;

    return 0;
}
